package com.houzehui.product.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.houzehui.product.entity.SpecGroup;
import com.houzehui.product.mapper.SpecGroupMapper;
import com.houzehui.product.service.ISpecGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.houzehui.product.vo.SpecGroupVo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 规格参数的分组表，每个商品分类下有多个规格参数组 服务实现类
 * </p>
 *
 * @author houzehui
 * @since 2022-04-27
 */
@Service
public class SpecGroupServiceImpl extends ServiceImpl<SpecGroupMapper, SpecGroup> implements ISpecGroupService {


    @Override
    public List<SpecGroup> getSpecGroup(Long categoryId) {
        List<SpecGroup> specGroups = list(new QueryWrapper<SpecGroup>().eq("cid", categoryId));

        return specGroups;
    }

    private SpecGroupVo toSpecGroupVo(SpecGroup specGroup){
        SpecGroupVo specGroupVo = new SpecGroupVo();
        BeanUtil.copyProperties(specGroup,specGroupVo);
        return specGroupVo;

    }

    @Override
    public List<SpecGroupVo> getSpecGroupVo(Long categoryId) {
        List<SpecGroup> specGroup = getSpecGroup(categoryId);
        ArrayList<SpecGroupVo> specGroupVos = new ArrayList<>();
        specGroup.forEach(s->{
            SpecGroupVo specGroupVo = toSpecGroupVo(s);
            specGroupVos.add(specGroupVo);
        });
        return specGroupVos;
    }


}
